import { reactive,onMounted } from 'vue'
import axios from 'axios'

export default function () {
    //数据

    //https://dog.ceo/api/breed/pembroke/images/random
    let dogList = reactive([
        'https://images.dog.ceo//breeds//pembroke//n02113023_8021.jpg'
    ])

    // console.log(1)

    //钩子函数
    onMounted( async () => {
        try {
            const res = await axios.get("https://dog.ceo/api/breed/pembroke/images/random")
            // console.log(res.data.message)
            dogList.push(res.data.message)
        } catch (error) {
            alert(error)
        }
    })

    //再来一只dog
    async function getDog() {
        try {
            const res = await axios.get("https://dog.ceo/api/breed/pembroke/images/random")
            // console.log(res.data.message)
            dogList.push(res.data.message)
        } catch (error) {
            alert(error)
        }
    }

    return { dogList, getDog }
}